package controllers;

import connectivity.Dbmanager;
import connectivity.QueryManager;
import java.io.*;
import java.util.LinkedList;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.JOptionPane;
import models.User;
import models.Vraag;
import tools.Encryptor;

public class SelfTestController extends HttpServlet {

    private Dbmanager dbManager;
    private QueryManager queryManager;
    HttpSession sessie;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        sessie = request.getSession();

        dbManager = new Dbmanager();
        dbManager.openConnection();
        queryManager = new QueryManager(dbManager);
        LinkedList vragen = new LinkedList<Vraag>();

        int module_id = 0;
        int course_id = 0;

        if (request.getParameter("moduleid") != null) {
            module_id = Integer.parseInt(request.getParameter("moduleid"));
        }
        if (request.getParameter("courseid") != null) {
            course_id = Integer.parseInt(request.getParameter("courseid"));
        }

        if (course_id != 0) {
            vragen = queryManager.getSelftestbycourse(course_id);
        } else if (module_id != 0) {
            vragen = queryManager.getSelftestbymodule(module_id);
        }

        request.setAttribute("vragen", vragen);


        String address = "/selftest.jsp";
        dbManager.closeConnection();
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response); //Stuurt door naar de Gebruikers index

    }
}
